<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        X-admin v1.0
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="__CSS__/x-admin.css" media="all">
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>会员管理</cite></a>
              <a><cite>管理员列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:80%">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
                <label class="layui-form-label">日期范围</label>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="开始日" id="start">
                </div>
                <div class="layui-input-inline">
                    <input class="layui-input" placeholder="截止日" id="end">
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="username" placeholder="请输入登录名" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
        </div>
    </form>
    <div>
        <button class="layui-btn layui-btn-danger delAll"><i class="layui-icon">&#xe640;</i>批量删除</button>
        <button class="layui-btn add"><i class="layui-icon">&#xe608;</i>添加</button>
    </div>
    <table id="admin_user" lay-filter="admin_user" class="layui-table"></table>
</div>
<script src="__LIB__/layui/layui.js" charset="utf-8"></script>
<script src="__JS__/x-layui.js" charset="utf-8"></script>


<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use(['laydate', 'element', 'table', 'layer'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element;//面包导航
        layer = layui.layer;//弹出层
        table = layui.table;
        //以上模块根据需要引入

        table.render({
            elem: "#admin_user",
            page: true,
            url: '{:url("admin.admin/index")}',
            height: 600,
            cols: [[
                {field: 'id', title: '编号'},
                {field: 'admin_name', title: "用户名"},
                {field: 'admin_email', title: "邮箱"},
                {field: 'admin_last_ip', title: "上次登录ip"},
                {field: 'admin_last_time', title: "上次登录时间"},
                {field: 'admin_avatar', title: "头像"},
                {field: 'admin_register', title: "注册时间"},
                {field: 'admin_status', title: "用户状态"},
                {field:'id',title:'操作',toolbar:"#bar",width:200}
            ]],
        });
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });
        });

        table.on('tool(admin_user)',function(obj){
            var data=obj.data;
            switch (obj.event) {
                case 'detail':
                    show_row(data.id);
                    break;
                case 'del':
                    del_row(data.id);
                    break;
                case 'edit':
                    edit_row(data.id);
                    break;
            }
        });


        /*添加*/
        $('.add').on('click',function(){
            x_admin_show("添加","{:url('/admin/managerList/add')}",800,600);
        });

        //编辑
        function admin_edit(title, url, id, w, h) {
            x_admin_show(title, url, w, h);
        }

        /*用户-停用*/
        function member_stop(obj,id){
            layer.confirm('确认要停用吗？',function(index){

                if($(obj).attr('title')=='启用'){

                    //发异步把用户状态进行更改
                    $(obj).attr('title','停用')
                    $(obj).find('i').html('&#xe62f;');

                    $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                    layer.msg('已停用!',{icon: 5,time:1000});

                }else{
                    $(obj).attr('title','启用')
                    $(obj).find('i').html('&#xe601;');

                    $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                    layer.msg('已启用!',{icon: 5,time:1000});
                }

            });
        }

        /*用户-删除*/
        function member_del(obj,id){
            layer.confirm('确认要删除吗？',function(index){
                //发异步删除数据
                $(obj).parents("tr").remove();
                layer.msg('已删除!',{icon:1,time:1000});
            });
        }


        function buildSearch(array){
            return $.param(array);
        }
        function delAll (argument) {

            var data = tableCheck.getData();

            layer.confirm('确认要删除吗？'+data,function(index){
                //捉到所有被选中的，发异步进行删除
                layer.msg('删除成功', {icon: 1});
                $(".layui-form-checked").not('.header').parents('tr').remove();
            });
        }
        function show_row(id){
            x_admin_show("登录日志","{:url('admin.admin/edit')}"+"?"+buildSearch({id:id}));
        }
        function edit_row(id){
            x_admin_show("修改","{:url('admin.admin/edit')}"+"?"+buildSearch({id:id}));
        }
        function del_row(id){
            layer.confirm('确定删除?',function(index){
                $.post("{:url('admin.admin/del')}",{id:id},function (repsonse) {
                    layer.msg(response.msg);
                    if(repsonse.code==1){
                        layer.close(index);
                    }
                })
            })
        }
    });

</script>
</body>
</html>